import {createWebHistory, createRouter} from 'vue-router'

const routes = [
    {
        path: '/',
        redirect: '/layout/home',
    },
    {
        path: '/layout',
        meta: {
            title: '首页',
            requireAuth: true,
        },
        redirect: '/layout/home',
        component: () => import('@/layout/Layout.vue'),
        children: [
            {
                path: 'home',
                meta: {
                    requireAuth: true,
                    isClosable: false,
                    title: '首页'
                },
                name: 'home',
                component: () => import('@/views/Home.vue'),
            },
            {
                path: 'system',
                redirect: '/layout/system/user',
                meta: {
                    requireAuth: true,
                    title: '系统管理',
                    isClosable: true
                },
                name: 'system',
                children: [
                    {
                        path: 'user',
                        meta: {
                            requireAuth: true,
                            title: '用户管理',
                            isClosable: true
                        },
                        name: 'system:user',
                        component: () => import('@/views/system/SysUser.vue'),
                    },
                    {
                        path: 'role',
                        meta: {
                            requireAuth: true,
                            title: '角色管理',
                            isClosable: true
                        },
                        name: 'system:role',
                        component: () => import('@/views/system/SysRole.vue'),
                    },
                    {
                        path: 'menu',
                        meta: {
                            requireAuth: true,
                            title: '菜单管理',
                            isClosable: true,
                        },
                        name: 'system:menu',
                        component: () => import('@/views/system/SysMenu.vue'),
                    }]
            },
            {
                path: 'book',
                redirect: '/layout/book/list',
                meta: {
                    requireAuth: true,
                    title: '图书管理',
                    isClosable: true
                },
                name: 'book',
                children: [
                    {
                        path: 'list',
                        meta: {
                            requireAuth: true,
                            title: '图书列表',
                            isClosable: true
                        },
                        name: 'book:list',
                        component: () => import('@/views/book/BookList.vue'),
                    },
                    {
                        path: 'category',
                        meta: {
                            requireAuth: true,
                            title: '图书分类',
                            isClosable: true
                        },
                        name: 'book:category',
                        component: () => import('@/views/book/BookCategory.vue'),
                    }
                ]
            },
            {
                path: 'reader',
                redirect: '/layout/reader/list',
                meta: {
                    requireAuth: true,
                    title: '读者管理',
                    isClosable: true
                }
                ,
                name: 'reader',
                children: [
                    {
                        path: 'list',
                        meta: {
                            requireAuth: true,
                            title: '读者列表',
                            isClosable: true
                        },
                        name: 'reader:list',
                        component: () => import('@/views/reader/ReaderList.vue'),
                    },
                    {
                        path: 'type',
                        meta: {
                            requireAuth: true,
                            title: '读者类型',
                            isClosable: true
                        },
                        name: 'reader:type',
                        component: () => import('@/views/reader/ReaderType.vue'),
                    }
                ]
            },
            {
                path: 'borrow',
                redirect: '/layout/borrow/list',
                meta: {
                    requireAuth: true,
                    title: '借阅管理',
                    isClosable: true
                },
                name: 'borrow',
                children: [
                    {
                        path: 'list',
                        meta: {
                            requireAuth: true,
                            title: '借阅列表',
                            isClosable: true
                        },
                        name: 'borrow:list',
                        component: () => import('@/views/borrow/BorrowRecordList.vue'),
                    },
                    {
                        path: 'borrow:book',
                        meta: {
                            requireAuth: true,
                            title: '借阅图书',
                            isClosable: true
                        },
                        name: 'borrow:borrow',
                        component: () => import('@/views/borrow/BorrowBook.vue'),
                    }
                ]
            },
            {
                path: 'person',
                redirect: '/layout/person/center',
                meta: {
                    requireAuth: true,
                    title: '个人中心',
                    isClosable: true
                },
                name: 'person',
                children: [
                    {
                        path: 'center',
                        meta: {
                            requireAuth: true,
                            title: '用户列表',
                            isClosable: true
                        },
                        name: 'person:center',
                        component: () => import('@/views/person/PersonCenter.vue'),
                    }
                ]
            },
            {
                path: 'statistic',
                redirect: '/layout/statistic/book',
                meta: {
                    requireAuth: true,
                    title: '统计',
                    isClosable: true
                },
                name: 'statistic',
                children: [
                    {
                        path: 'book',
                        meta: {
                            requireAuth: true,
                            title: '图书统计',
                            isClosable: true
                        },
                        name: 'statistic:book',
                        component: () => import('@/views/statistic/BookStatistic.vue'),
                    },
                    {
                        path: 'borrow',
                        meta: {
                            requireAuth: true,
                            title: '借阅统计',
                            isClosable: true
                        },
                        name: 'statistic:borrow',
                        component: () => import('@/views/statistic/BorrowStatistic.vue'),
                    },
                    {
                        path: 'reader',
                        meta: {
                            requireAuth: true,
                            title: '读者统计',
                            isClosable: true
                        },
                        name: 'statistic:reader',
                        component: () => import('@/views/statistic/ReaderStatistic.vue'),
                    }
                ]
            }
        ]
    },
    {
        path: '/login',
        component: () => import('@/views/Login.vue'),
    },
    {
        path: '/404',
        meta: {
            requireAuth: false,
            title: '404',
            isClosable: false
        },
        name: '404',
        component: () => import('@/views/404.vue'),
    },
    {
        path: '/403',
        meta: {
            requireAuth: false,
            title: '403',
            isClosable: false
        },
        name: '403',
        component: () => import('@/views/403.vue'),
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes,
})
export default router;
